#pragma once

#include <atlcrack.h>
#include <atlctrls.h>
#include <atlmisc.h>

template< class T > class VirtualListView : public CWindowImpl< T, CListViewCtrl, CControlWinTraits >
{
public:
    DECLARE_WND_SUPERCLASS(NULL, CListViewCtrl::GetWndClassName())

    LRESULT OnGetDispInfo(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
    {
        NMLVDISPINFO *pInfo = (NMLVDISPINFO *)pnmh;
        if(pInfo->item.mask & LVIF_TEXT)
        {
            T* _this = (T*)this;
            _tcscpy( pInfo->item.pszText, _this->GetItemText(pInfo->item.iItem, pInfo->item.iSubItem).c_str() );
        }

        bHandled = TRUE;
        return 0;
    }

    BEGIN_MSG_MAP_EX( VirtualListView<T> )
        REFLECTED_NOTIFY_CODE_HANDLER(LVN_GETDISPINFO, OnGetDispInfo)
    END_MSG_MAP()
};